package com.shujia.source

import org.apache.flink.streaming.api.scala._

object Demo03SocketSource {
  def main(args: Array[String]): Unit = {

    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

    // 以Socket最为Source构建DataStream --> 无界流
    val lineDS: DataStream[String] = env.socketTextStream("master", 8888)

    /**
     * Flink中的算子没有action或者transformation之分
     * Flink的任务不需要action算子触发执行
     */
    lineDS
      .flatMap(line => {
        println("flatMap")
        line.split(",")
      })
      .map(word => (word, 1))
      .keyBy(kv => kv._1)
      .sum(1)
      .print()

    env.execute()

  }

}
